﻿using Microsoft.AspNetCore.Builder;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace MyApp.WebApi.Extensions
{
    public static class SwaggerMildd
    {
        public static void UseSwaggerMildd(this IApplicationBuilder app, Func<Stream> streamHtml)
        {
            if (app == null) throw new ArgumentNullException(nameof(app));
            app.UseSwagger();
            app.UseSwaggerUI(c => {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "MyApp.WebApi v1");
                c.RoutePrefix = "";//直接index.html 
                c.IndexStream = streamHtml;
                //    c.HeadContent = @$"<script async='async' id='mini-profiler' src='/profiler/includes.min.js?v=4.1.0+c940f0f28d'
                //    data-version='4.1.0+c940f0f28d' data-path='/profiler/'
                //    data-current-id='4ec7c742-49d4-4eaf-8281-3c1e0efa8888' data-ids='4ec7c742-49d4-4eaf-8281-3c1e0efa8888'
                //    data-position='Left'
                //    data-authorized='true' data-max-traces='5' data-toggle-shortcut='Alt+P'
                //    data-trivial-milliseconds='2.0' data-ignored-duplicate-execute-types='Open,OpenAsync,Close,CloseAsync'>
                //</script>";
            });
        }
    }
}
